<?php

namespace app\admin\model;

use think\Db;
use think\Model;

class Allot extends Model
{
    // 表名
    protected $name = 'allot';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [

    ];
    public function getStatusList()
    {
        return ['0' => __('Status 0'),'1' => __('Status 1'),'2' => __('Status 2'),'3' => __('Status 3'),'4' => __('Status 4'),'5' => __('Status 5'),'6' => __('Status 6')];
    }
    public function getTypeList()
    {
        return ['1' => __('Typelist 1'),'2' => __('Typelist 2'),'3' => __('Typelist 3'),'4' => __('Typelist 4')];
    }











    public function buser()
    {
        return $this->belongsTo('Buser', 'buser_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function bkuser()
    {
        return $this->belongsTo('Bkuser', 'buser_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function admin()
    {
        return $this->belongsTo('Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function product()
    {
        return $this->belongsTo('Product', 'product_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    /**
     * @param $buser_id
     * logic:是否有线索，有则第二个负责人期限15天
     */
    function get_expire_date($buser_id)
    {
        if(Db::name('allot')->where('buser_id',$buser_id)->find())
        {
            $where['id']=2;
        }else{
            $where['id']=1;
        }
        return Db::name('allot_expire')->where($where)->value('expire');
    }
}
